#pragma once
#include <string>
#include <vector>
#include <functional>
#include <cstdint>

// Minimal MJPEG Web server (single-threaded accept + per-client thread)
class WebMJPEGServer {
public:
    explicit WebMJPEGServer(int port = 8080);
    ~WebMJPEGServer();

    // Frame provider returns a JPEG buffer for the current frame
    void setFrameProvider(std::function<std::vector<uint8_t>()> provider);

    // Optional: stats html provider for /stats endpoint, and time for /stats_time
    void setStatsProvider(std::function<std::string()> stats_html_provider,
                          std::function<std::string()> time_provider);

    // Optional: JSON stats provider for /stats_json endpoint
    void setStatsJsonProvider(std::function<std::string()> stats_json_provider);

    void start();
    void stop();
    bool isRunning() const;

    // Number of currently connected MJPEG clients
    int getClientCount() const;

private:
    struct Impl;
    Impl* impl_;
};
